﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using Microsoft.Xna.Framework;
using System.Reflection;
using System.Web;
using System.Collections.Specialized;
using StreetlightGames.XnaEngine;
using StreetlightGames.SpaceShooter.Enemies;

namespace StreetlightGames.SpaceShooter.Patterns
{
    [KnownType(typeof(Attack))]
    [KnownType(typeof(ArmWeapons))]
    [KnownType(typeof(ContinueForward))]
    [KnownType(typeof(FlyInCircle))]
    [KnownType(typeof(Hover))]
    [KnownType(typeof(MoveToFormation))]
    [KnownType(typeof(MoveToTarget))]
    [DataContract]
    public class Pattern
    {
        /// <summary>Gets or sets the Ship value</summary>
        public EnemyShip Ship
        {
            get { return _ship; }
            set
            {
                _ship = value;
                Start();
            }
        }
        private EnemyShip _ship;

        /// <summary>Gets or sets the NextPattern value</summary>
        [DataMember]
        public Pattern NextPattern
        {
            get { return _nextPattern; }
            set { _nextPattern = value; }
        }
        private Pattern _nextPattern;
        
        public Pattern()
        {
        }

        public virtual void Update(GameTime gameTime)
        {
        }

        public virtual void Start()
        {
        }

        protected void MoveToNextPattern(GameTime gameTime)
        {
            Ship.Pattern = NextPattern;
            if (Ship.Pattern != null)
            {
                Ship.Pattern.Update(gameTime);
            }
        }

        public override string ToString()
        {
            return GetType().Name;
        }
    }
}
